
// This program demonstrates how to get character outlines, 
//  modify them and plot them.

// In this example, the character outline is obtained, then
//   modified by slanting it forward or backward, 
//   reflecting it and/or flipping it.

INCLUDE "standard_colors.txt"
// (make sure you have downloaded this file)
DEGREES
DIM array (10,2)

// Try different values of slant, reflect and flip
slant = -.2		// 0 is upright, + = slant right, - = left
reflect = 1		// 1 = normal, -1 = reflect horiz.
flip    = 1		// 1 = normal, -1 = flip vert.

GRAPH EQUALSCALES
GRAPH INCLUDEXAXIS=0, INCLUDEYAXIS=0 
GRAPH WIDTH=6, HEIGHT=6
SHAPE FONT = "Times New Roman"
SHAPE CHARACTERS = "R"
SHAPE LEFT = 100,   RIGHT = 100
SHAPE BOTTOM = 100, TOP   = 200
SHAPE BOLD = 100, ITALIC = 0
SHAPE ROTATE = 0
SHAPE POLYPOINTS = array
SHAPE CHAROUTLINE
// Now array has new dimensions, and contains the outline.

// "Modify" the points in the array

i = 0
num_contours   = array(i, 0)              // number of contours
m              = array(i, 1)              // metrics offset
h   = array(m+3, 1) - array (m+2, 1) 	  // height
cx  = (array(m+2, 0) + array (m+1, 0))/2  // horiz center
b   = array(m+1, 1) 		 	  // base
cy  = b + h/2			 	  // vert center

i = i + 1
WHILE num_contours > 0  
  // Since we are only modifying the points, we can treat the
  // Polyline and Bezier curves the same.  
  num_curves = array(i,0) // number of curves in this contour.
  i = i + 1
  // next point is start point for this contour.  Modify it.
  x = array(i,0):  y = array(i,1)  // get the point
  x = x * (1 + slant * (y-b) / h)  // slant   the point
  x = (x - cx) * reflect + cx	   // reflect the point
  y = (y - cy) * flip    + cy	   // flip    the point
  array(i,0) = x: array (i,1) = y  // put it back
  i = i + 1

  WHILE num_curves > 0
    num_points = array(i,0)	// number of points in curve
    i = i + 1

    WHILE num_points > 0
      x = array(i,0):  y = array(i,1)	   // get the point
      x = x * (1 + slant * (y-b) / h)      // slant   the point
      x = (x - cx) * reflect + cx	   // reflect the point
      y = (y - cy) * flip    + cy	   // flip    the point
      array(i,0) = x: array (i,1) = y	   // put it back
      i = i + 1
      num_points = num_points - 1
    WEND 		// end of curve (polyline or Bezier)
    num_curves = num_curves - 1
  WEND  		// end of contour
  num_contours = num_contours - 1
WEND 			// end of shape

SHAPE ROTATE = 0
SHAPE FILLTYPE = SOLID, FILLCOLOR = red
SHAPE LINECOLOR = black

SHAPE PLOTCHAROUTLINE
END

